package com.ccx.coachsite.weibo.auth2.net;


import java.io.Serializable;

import com.ccx.coachsite.weibo.json.JSONException;
import com.ccx.coachsite.weibo.json.JSONObject;


/**
 * 登陆返回的数据对象
 * @author zhuchenghua
 *
 */
public class Token implements Serializable{
	
	
	private static final long serialVersionUID = -6970273523217298627L;
	
	/**
	 * 访问密钥
	 */
	private String accessToken;
	/**
	 * 有效时限
	 */
	private long expiresIn;
	/**
	 * 剩余时限
	 */
	private long remindIn;
	/**
	 * 用户ID
	 */
	private String uid;
	
	public Token(String jsonString) throws Exception{
		try {
			JSONObject jobj=new JSONObject(jsonString);
			constructToken(jobj);
		} catch (Exception e) {
			throw new Exception("Create Token instance failed!",e);
		}
		
	}
	
	public Token(JSONObject jobj) throws Exception
	{
		try {
			constructToken(jobj);
		} catch (JSONException e) {
			throw new Exception("Create Token instance failed!",e);
		}
	}
	
	private void constructToken(JSONObject jobj) throws JSONException
	{
		if(jobj==null)
			return;
		this.accessToken=jobj.getString("access_token");
		this.expiresIn=jobj.getLong("expires_in");
		this.remindIn=jobj.getLong("remind_in");
		this.uid=jobj.getString("uid");
	}

	public String getAccessToken() {
		return accessToken;
	}

	public void setAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}

	public long getExpiresIn() {
		return expiresIn;
	}

	public void setExpiresIn(long expiresIn) {
		this.expiresIn = expiresIn;
	}

	public long getRemindIn() {
		return remindIn;
	}

	public void setRemindIn(long remindIn) {
		this.remindIn = remindIn;
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}
	
	
	
}


















